package kz.pompei.ifacer.main;

import java.awt.Frame;

import javax.swing.JFrame;

public enum WindowState {
  NORMAL, MAXI_HORIZ, MAXI_VERT, MAXI_BOTH;
  
  public static WindowState convert(int state) {
    if (state == Frame.MAXIMIZED_HORIZ) return MAXI_HORIZ;
    if (state == Frame.MAXIMIZED_VERT) return MAXI_VERT;
    if (state == Frame.MAXIMIZED_BOTH) return MAXI_BOTH;
    return NORMAL;
  }
  
  public int toInt() {
    switch (this) {
    case MAXI_HORIZ:
      return Frame.MAXIMIZED_HORIZ;
    case MAXI_VERT:
      return Frame.MAXIMIZED_VERT;
    case MAXI_BOTH:
      return Frame.MAXIMIZED_BOTH;
    default:
      return Frame.NORMAL;
    }
  }
  
  public static WindowState byName(String name, WindowState defaultValue) {
    for (WindowState ws : values()) {
      if (ws.name().equals(name)) return ws;
    }
    return defaultValue;
  }
  
  public void applyTo(JFrame frame) {
    frame.setExtendedState(toInt());
  }
}
